<#macro chooseDlg id title url>

<div class="modal " id="${id}Dlg" tabindex="-1" role="dialog" aria-labelledby="${id}DlgTitle" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="${id}DlgTitle">${title}</h4>
        <div class="modal-body" id="${id}ListContainer">
        	
      	</div>
      	<div class="modal-footer">
      	<button type="button" class="btn btn-primary" id="btn-${id}AddSure">是</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">否</button>        
      </div>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript">
$('#${id}ListContainer').on("click",'tr',function(){
	var radio=$('input[name=selectId]',this);
	radio.prop("checked",!radio.prop("checked"));
});
var _${id}={
	selectedId:'',
	selectedName:'',
	showChooseDlg:function(selectedId,selectedName)
	{
		$.get('${url}&pageSize=5',{},this.afterLoadData,'html');
		$('#${id}Dlg').modal('show');			
		this.selectedId=selectedId;
		this.selectedName=selectedName;
	},
	
	clean:function(){
		$.each($('#${id}ListContainer [name="selectId"]'),function(index,ele){
				$(ele).prop("checked",false);				
			});
	},
	
	hiden:function(){
		$('#${id}Dlg').modal('hide');		
	},
	
	display:function(){
		$('#${id}Dlg').modal('show');		
	},
	
	showSchemaDlg:function(selectedId,selectedName,schemaType)
	{
		$.get('${url}&pageSize=5&schemaType='+schemaType,{},this.afterLoadData,'html');
		$('#${id}Dlg').modal('show');			
		this.selectedId=selectedId;
		this.selectedName=selectedName;
	},
	afterLoadData:function(data)
	{
		$('#${id}ListContainer').empty();
		$('#${id}ListContainer').append(data);
		if(_${id}.selectedId)
		{
			$.each($('#${id}ListContainer [name="selectId"]'),function(index,ele){
				if(_${id}.selectedId==ele.value)
					$(ele).prop("checked",true);				
			});
		}
		//$('#${id}Dlg').on('hidden.bs.modal', function (e) {
		//	$('#${id}ListContainer').empty();
		//});	
	},
	toPage:function(params)
	{
		this._getData();
		$.get('${url}',params,this.afterLoadData,'html'); 	  	
	},
	_getData:function()
	{
		var checked=$('#${id}ListContainer :checked');
		if(checked.length>0)
		{
			this.selectedId=checked[0].value;
			this.selectedName=checked.parent().siblings()[0].innerText;
		}
		
	},
	getData:function()
	{
		var checked=$('#${id}ListContainer :checked');
		if(checked.length>0)
		{
			this.selectedId=checked[0].value;
			this.selectedName=checked.parent().siblings()[0].innerText;
		}
		else
		{
			this.selectedId=undefined;
			this.selectedName='';
		}
		$('#${id}Dlg').modal('hide');	
		return {id:this.selectedId,name:this.selectedName};
	}
}
</script>
</#macro>